﻿Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Seuss.EnterpriseLibrary.DataAccess
Imports Seuss.EnterpriseLibrary.BusinessLogic
Imports System.Web
Imports System.Data
Imports System.Collections.Generic

Partial Class Consulta_AL_CursoActual_Cons
    Inherits System.Web.UI.Page
    Dim nCurGruCodigo As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.QueryString("nCurGruCodigo") Is Nothing Or Request.QueryString("nCurGruCodigo") Is String.Empty Then
            If Session("nCurGruCodigo") Is Nothing Or Session("nCurGruCodigo") Is String.Empty Then
                Response.Redirect("AL_InfoAcad_CA.aspx")
            Else
                nCurGruCodigo = Session("nCurGruCodigo")
            End If
        Else
            Session("nCurGruCodigo") = Request.QueryString("nCurGruCodigo")
            nCurGruCodigo = Request.QueryString("nCurGruCodigo")
        End If
        Response.Expires = -1
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("cache-control", "private")
        Response.CacheControl = "no-cache"
        lnkRegresar_3.HRef = "./AL_CursoActual.aspx?nCurGruCodigo=" + nCurGruCodigo
        lnkRegresar_4.HRef = "./AL_CursoActual.aspx?nCurGruCodigo=" + nCurGruCodigo

        If Not Page.IsPostBack Then
            CargarConsultasRptas()
            Using Seguridad As New BLL_Administracion
                Seguridad.Set_Transaccion_Insert(Nothing, 100401, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Consulta Pagina Movil", "/Pagina|" + My.Request.Url.Segments(My.Request.Url.Segments.Length - 1).ToString))
            End Using
        End If
    End Sub

    Private Sub CargarConsultasRptas()
        Dim DivConsultas As New StringBuilder
        Dim ldrpregunta As New List(Of IDataReader)
        Using ObjPool As New PoolDbCommand()
            Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(Objgrupo.Get_ConsultasAndRespuestas(nCurGruCodigo, 2000, 1, IdentityUser.UserCode), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldrpregunta, True)
        End Using
        While ldrpregunta(0).Read
            DivConsultas.Append("<div class=""listview""><ul>")
            DivConsultas.Append("<li>")
            DivConsultas.Append("<p></p>")
            DivConsultas.Append("<p class=""fecha"">" & ldrpregunta(0).Item("FechaEnvio") & "</p>")
            DivConsultas.Append("<p><strong>" & ldrpregunta(0).Item("EnviadoPor") & "</strong></p>")
            DivConsultas.Append("<p style=""white-space:normal; text-align:justify"">" & ldrpregunta(0).Item("Pregunta") & "</p>")
            If Len(ldrpregunta(0).Item("Respuesta").ToString) > 0 Then
                DivConsultas.Append("<br/><p>Respondida por: <strong>" & ldrpregunta(0).Item("PersonaRespuesta") & "</strong></p>")
                DivConsultas.Append("<p style=""white-space:normal; text-align:justify"">" & ldrpregunta(0).Item("Respuesta") & "</p>")
                DivConsultas.Append("<p>" & ldrpregunta(0).Item("FechaRespuesta") & "</p>")

            End If
            DivConsultas.Append("<br/></li>")
            DivConsultas.Append("</ul></div>")
        End While
        lblcontenido.Text = DivConsultas.ToString
        ldrpregunta(0).Close()
        ldrpregunta(0) = Nothing
    End Sub

    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        Using ObjPool As New PoolDbCommand()
            Dim Objgrupo As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(Objgrupo.Ins_Cam_Help(CapturaCurGrupoBase(Session("ncurgrucodigo")), CapturaCurGrupoBase(Session("ncurgrucodigo")), 2000, txtconsulta.Text, IdentityUser.UserCode, 2001), PoolDbCommand.PoolDbCommandResultType.NonQuery)
            If ObjPool.Pooling() Then
                Using Seguridad As New BLL_Administracion
                    Seguridad.Set_Transaccion_Insert(Nothing, 100405, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Registrar Consulta", "/nCurGurCodigo|" + CStr(CapturaCurGrupoBase(Session("ncurgrucodigo")))))
                End Using
            End If
        End Using
        txtconsulta.Text = ""
        Response.Redirect("AL_CursoActual_Cons.aspx?nCurGruCodigo=" & nCurGruCodigo)
    End Sub

    Public Function CapturaCurGrupoBase(ByVal nCurGruCodigo As Long) As Long
        Dim VCurGrupoBase As Long = 0
        Dim ldr As New List(Of IDataReader)
        Using ObjPool As New PoolDbCommand()
            Dim ObjMenu As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjMenu.Get_nCurGruCodigoBase_By_nCurgruCodigo(nCurGruCodigo), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldr, True)
            If ldr(0).Read Then
                VCurGrupoBase = ldr(0).GetInt32(0)
            Else
                VCurGrupoBase = nCurGruCodigo
            End If
        End Using
        ldr(0).Close()
        ldr(0) = Nothing
        Return VCurGrupoBase
    End Function

End Class